//
//  HJBaseTableViewController.swift
//  Micro-blog Sina
//
//  Created by admin on 16/3/20.
//  Copyright © 2016年 admin. All rights reserved.
//

import UIKit

class HJBaseTableViewController: UITableViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        
        
    }
    // User login flag
    var userLogin = HJUserAccountViewModel.sharedInstance.userLogin
    override func loadView() {
        userLogin ? super.loadView() : setupVisitorView()
    }
    private func setupVisitorView() {
        visitorView = HJVisitorView()
        view = visitorView
        // 4. Setting agent
        visitorView.delegate = self
        
        // Determine which controller is currently
        if self is HJHomeViewController {
            visitorView.startRotationAnimation()
        }else if self is HJMessageViewController {
            visitorView.setupVisitorInfo("visitordiscover_image_message", message: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        }else if self is HJDiscoverViewController {
            visitorView.setupVisitorInfo("visitordiscover_image_message", message: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        }else if self is HJProfileViewController {
            visitorView.setupVisitorInfo("visitordiscover_image_profile", message: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        }
        
        
        // Add navigation bar button
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewRegisterBtnClick")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewLoginBtnClick")
    }
    
    // MARK: - Lazy load
    // Custom visitor views
    private lazy var visitorView: HJVisitorView = HJVisitorView()
}

// MARK: - HJVisitorViewDelegate
extension HJBaseTableViewController: HJVisitorViewDelegate {
    // MARK: - Realizing agent method
    func visitorViewRegisterBtnClick() {
        print("HJBaseTableViewController:\(__FUNCTION__)")
    }
    func visitorViewLoginBtnClick() {
        print("HJBaseTableViewController:\(__FUNCTION__)")
        let OauthVC = HJOauthViewController()
        presentViewController(UINavigationController(rootViewController: OauthVC), animated: true, completion: nil)
    }
}
